const connection = require('../../db/index')
const express = require("express");
const getbook = express.Router();
//计算机 获取数据
getbook.get('/getjisuanji',(req,res) => {
    var page = req.query.pagenum
    var size = req.query.pagesize
    var start = (page - 1) * size;
    var note = req.query.query
    if(note) {
        connection.query('SELECT * FROM jisuanji where name like "%'+note+'%" or author like "%'+note+'%"', function(err, rows, fields) {
            if (err) {
                throw err
            }
            var total = rows.length
            var List = rows
            if(List) {
                res.send({
                    total,
                    List,
                    stats:200
                })
            }           
        })
    }else {
        connection.query('SELECT * FROM jisuanji; SELECT * FROM jisuanji limit ' + start + ',8;', function(err, rows, fields) {
            if (err) {
                throw err
            }
            var total = rows[0].length
            var List = rows[1]
            res.send({
                List,
                total,
                stats:200
            })
        })
    }
    
})

module.exports = getbook